﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Entity;

namespace GSLMS.WebAPP.Areas.RiskAudit.Controllers.Audit.AuditAssign
{
    public class AuditAssignController : AdminBaseController
    {
        protected override string navTabId
        {
            get { return "RiskAudit_Audit_AuditAssign"; }
        }


        //[HttpGet]
        //public ActionResult Index()
        //{
        //    var searchParam = base.SearchPara<TB_APP_PROINFO>(form, new TB_APP_PROINFO());
        //    searchParam.StrSort = " id desc";
        //    searchParam.RiskDealingStatus = 1;

        //    var model = serviceProInfo.GetAduAssignList(searchParam);
        //   // searchParam.StrSort = " id desc";
        //    ViewData["RowCount"] = searchParam.RowCount;

        //    ViewData["SearchParma"] = searchParam;
        //    InitSelect();
        //    return View(model);
        //}

        //[HttpPost]
        public ActionResult Index(FormCollection form)
        {
            var searchParam = base.SearchPara<TB_APP_PROINFO>(form, new TB_APP_PROINFO());
            searchParam.StrSort = " id desc";
            var model = serviceProInfo.GetAduAssignList(searchParam);
            ViewData["RowCount"] = searchParam.RowCount;
            InitSelect();
            return View(model);
        }

        protected void InitSelect()
        {
            ViewData["DepID"] = new SelectList(serviceSysOrg.GetAllList(), "id", "orgname");
            ViewData["Product"] = new SelectList(serviceSysProduct.GetBySysetmID(GSLMS.Entity.Enum.SystemEnum.SystemID.典当, -1), "id", "productname");
        }

        //
        // GET: /DianDang/Assign/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /DianDang/Assign/Create

        public ActionResult Create(int id)
        {
            ViewData["UserEffList"] = serviceEmp.GetRiskAuditUserList(CurentUser.UserName);

            var model = serviceProInfo.GetAduAssignByID((long)id);

            ViewData["status"] = model.STATUS;

            return View(model);
        }

        //
        // POST: /DianDang/Assign/Create

        [HttpPost]
        public string Create(FormCollection collection)
        {
            string result = string.Empty;
            GSLMS.Entity.TB_ADU_ASSIGN model = new TB_ADU_ASSIGN();

            try
            {
                string flowUser = collection["FlowUser"];


                model.ID = 0;
                model.PROID = Request["id"] == null ? 0 : GSLMS.Core.Helper.ToLong(Request["id"]);
                model.ASSIGNBY = CurentUser.UserName;
                model.ASSIGNTIME = DateTime.Now;
                model.FLOWUSER = flowUser;


                bool isSumbit = false;
                isSumbit = serviceAduAssign.Add(model);
                if (isSumbit)
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }

            return "{" + result + "}";
        }

        //
        // GET: /DianDang/Assign/Edit/5

        public ActionResult Files(int id)
        {
            ViewData["ProID"] = id;
            return View();
        }

        //
        // POST: /DianDang/Assign/Edit/5

        [HttpPost]
        public ActionResult Files(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }



        [HttpPost]
        public string BackTo(int id)
        {
            string result = string.Empty;
            var model = new TB_APP_PROINFO();
            model.ID = (long)id;
            model.BACKBY = CurentUser.UserName;
            model.BACKREASON = "";
            try
            {
                bool isSumbit = false;
                isSumbit = serviceProInfo.AduitBackTo(model);

                if (isSumbit)
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }


            return "{" + result + "}";
        }

    }
}
